package com.ruoyi.disk.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.disk.domain.SysStorage;
import com.ruoyi.disk.domain.dto.RestoreDTO;
import com.ruoyi.disk.domain.vo.BackupFileVO;
import com.ruoyi.disk.domain.vo.BackupVO;
import com.ruoyi.disk.service.ISysBackupService;
import com.ruoyi.disk.service.ISysStorageService;

/**
 * 用户存储 Controller
 */
@RestController
@RequestMapping("/disk/storage")
public class SysStorageController extends BaseController {
    
    @Autowired
    private ISysStorageService sysStorageService;
    
    @Autowired
    private ISysBackupService sysBackupService;

    /**
     * 查询用户存储列表
     */
    @PreAuthorize("@ss.hasPermi('disk:storage:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysStorage sysStorage) {
        // 原有的实现...
        return null;
    }

    /**
     * 获取用户存储详情
     */
    @PreAuthorize("@ss.hasPermi('disk:storage:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        // 原有的实现...
        return AjaxResult.success();
    }

    /**
     * 新增用户存储
     */
    @PreAuthorize("@ss.hasPermi('disk:storage:add')")
    @PostMapping
    public AjaxResult add(@RequestBody SysStorage sysStorage) {
        // 原有的实现...
        return toAjax(1);
    }

    /**
     * 修改用户存储
     */
    @PreAuthorize("@ss.hasPermi('disk:storage:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody SysStorage sysStorage) {
        // 原有的实现...
        return toAjax(1);
    }

    /**
     * 删除用户存储
     */
    @PreAuthorize("@ss.hasPermi('disk:storage:remove')")
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        // 原有的实现...
        return toAjax(1);
    }
    
    /**
     * 格式化磁盘
     */
    @PreAuthorize("@ss.hasPermi('disk:storage:formattedDisk')")
    @DeleteMapping("/formattedDisk/{userId}")
    public AjaxResult formattedDisk(@PathVariable Long userId) {
        // 原有的实现...
        return toAjax(1);
    }
    
    /**
     * 创建用户磁盘备份
     */
    @PreAuthorize("@ss.hasPermi('disk:storage:backupDisk')")
    @PostMapping("/backup/{userId}")
    public AjaxResult backup(@PathVariable Long userId) {
        BackupVO backupVO = sysBackupService.createBackup(userId);
        return AjaxResult.success(backupVO);
    }
    
    /**
     * 获取用户备份列表
     */
    @PreAuthorize("@ss.hasPermi('disk:storage:listBackups')")
    @GetMapping("/backups/{userId}")
    public AjaxResult listBackups(@PathVariable Long userId) {
        List<BackupVO> backups = sysBackupService.listUserBackups(userId);
        return AjaxResult.success(backups);
    }
    
    /**
     * 获取备份文件列表
     */
    @PreAuthorize("@ss.hasPermi('disk:storage:listBackupFiles')")
    @GetMapping("/backups/{userId}/{backupId}/files")
    public AjaxResult listBackupFiles(@PathVariable("userId") Long userId, @PathVariable("backupId") String backupId) {
        List<BackupFileVO> files = sysBackupService.listBackupFiles(userId, backupId);
        return AjaxResult.success(files);
    }
    
    /**
     * 从备份恢复文件
     */
    @PreAuthorize("@ss.hasPermi('disk:storage:restoreFiles')")
    @PostMapping("/restore")
    public AjaxResult restore(@RequestBody RestoreDTO restoreDTO) {
        return AjaxResult.success(sysBackupService.restoreFiles(restoreDTO));
    }
} 